package com.kgcx.system.service;

import com.kgcx.system.domain.SysRoleMenu;
import com.kgcx.system.mapper.SysRoleMenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 何凯
 * @version 0.1
 * @description 系统角色菜单业务层
 * @time 2017/12/13 17:41
 * @since 0.1
 */
@Service
public class SysRoleMenuService {
    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;
    /**
     * 批量新增角色菜单
     * @param list
     */
    public void insertByBatch(List<SysRoleMenu> list){
        sysRoleMenuMapper.insertByBatch(list);
    }

     /**
     * 修改角色菜单
     * @param list
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateRoleMenu(List<SysRoleMenu> list){
        if (null!=list&&list.size()>0){
        SysRoleMenu roleMenu =list.get(0);
        sysRoleMenuMapper.deleteByRoleId(roleMenu.getRoleId());
        sysRoleMenuMapper.insertByBatch(list);
         }
    }
    /**
     * 根据id删除角色菜单
     * @param kid
     * @return
     */
    public int deleteByPrimaryKey(Integer kid){
        return sysRoleMenuMapper.deleteByPrimaryKey(kid);
    }

    /**
     * 根据角色ID删除角色菜单
     * @param roleId
     * @return
     */
    public int deleteByRoleId(Integer roleId){
        return sysRoleMenuMapper.deleteByRoleId(roleId);
    }
    /**
     * 根据角色ID查询角色菜单
     * @param roleId
     * @return
     */
    List<SysRoleMenu> queryListByRoleId(Integer roleId){
        return sysRoleMenuMapper.queryListByRoleId(roleId);
    }

    /**
     * 根据员工查询对应菜单
     * @param employeeId
     * @return
     */
    List<SysRoleMenu> queryListByEmployeeId(Integer employeeId){
        return sysRoleMenuMapper.queryListByEmployeeId(employeeId);
    }
}
